<?php

namespace plugin\kb_blog\app\api\controller;

use support\Request;
use support\Response;
use plugin\kb_blog\app\model\Project;

/**
 * 项目
 */
class ProjectController
{
    /**
     * 查询
     *
     * @param Request $request
     * @return Response
     */
    public function search(Request $request): Response
    {
        $param = $request->all();
        $Count = Project::count();
        $tol = ((int)$param["page"] - 1) * (int)$param["limit"];
        $Project = Project::where(function ($query) {
            if (isset($param["order"])) {
                foreach ($param["order"] as $k => $v) {
                    $query->orderBy($k, $v);
                }
            }
        })->offset($tol)->limit((int)$param["limit"])
            ->get();

        return json([
            "code" => 0,
            "msg" => "ok",
            "data" => [
                "count" => $Count,
                "data" => $Project
            ]
        ]);
    }
}
